#include <stdio.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char* argv[])
{
    printf("进程：%d\n", getpid());

    if(argc != 2)
    {
        printf("Usage: %s filename\n", argv[0]);
        return 2;
    }

    //修改文件创建路径
    //chdir("/home/yyc");
    //FILE *fp = fopen("log.txt", "w");
    FILE *fp = fopen(argv[1], "r");
    if(fp == NULL)
    {
        perror("fopen");
        return 1;
    }
    
    while(1)
    {
        char buffer[1024];
        buffer[0] = 0;
        size_t n = fread(buffer, 1, sizeof(buffer) - 1, fp);

        if(n > 0)
        {
            buffer[n] = 0;
            printf("%s", buffer);
        }
        else if(feof(fp))
        {
            break;
        }
    }


    //const char* str = "hello bit\n";
    //fwrite(str, strlen(str), 1, fp);
    //while(1);
    

    fclose(fp);


    return 0;
}
